<?php

namespace App\Models;

use App\Http\Constants\Account\CommonCoinCoinConstants;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CommonCoinCoin extends Model
{
    use HasFactory;

    protected $table = 'common_coin_coin';
    protected $appends = ['status_name'];

    protected $fillable = [
        'id',
        'member_id',
        'account_type',
        'investment_id',
        'status',
        'total_coin',
        'now_coin',
        'freeze_coin',
        'withdraw_coin',
        'today_increase',
        'today_decrease',
        'reserve_coin',
        'clear_date',
        'transfer_date',
        'create_time',
        'update_time',
        'remark',
        'version',
        'yesterday_increase',
        'subsidy_coin',
    ];

    protected $casts = [

    ];

    protected function getStatusNameAttribute()
    {
        $attributes = $this->attributes;
        $value = array_key_exists('status', $attributes) ? $attributes['status'] : null;
        if (is_null($value)) return null;
        $map = array_column(CommonCoinCoinConstants::ACCOUNT_TYPE, 'label', 'value');
        return array_key_exists($value, $map) ? $map[$value] : null;
    }

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

}
